{
  interface Element {
    data: any;
    code: number;
  }
  class Queue {
    private dataStore: Element[] = [];
    get length(): number {
      return this.dataStore.length;
    }
    enqueus(element: Element) {
      this.dataStore.push(element);
    }
    dequeus(): any | undefined {
      let priority = this.dataStore[0].code;
      let flag = false;
      for (let i = 1; i < this.dataStore.length; i++) {
        if (this.dataStore[i].code < priority) {
          flag = true;
          priority = i;
        }
      }
      return flag
        ? this.dataStore.splice(priority, 1)[0]
        : this.dataStore.shift();
    }
    front(): Element {
      return this.dataStore[0];
    }
    back(): Element {
      return this.dataStore[this.length - 1];
    }
    toString(): string {
      return this.dataStore
        .map((item) => item.data + "--" + item.code)
        .join("\n");
    }
    clear(): void {
      this.dataStore.length = 0;
    }
    isEmpty(): boolean {
      return this.length === 0;
    }
  }

  let que = new Queue();

  /**
   * 优先级一到5 1的最高 5最低
   */
  que.enqueus({ data: "吃饭", code: 2 });
  que.enqueus({ data: "睡觉", code: 2 });
  que.enqueus({ data: "打豆豆", code: 2 });
  que.enqueus({ data: "学习", code: 1 });
  console.log(que.dequeus());
  console.log(que.dequeus());
  console.log(que.toString());
}
